<template>
  <div class="sidebar-layout">
    <!-- 左侧边栏 -->
    <div class="sidebar" v-show="showSidebar">
      <!-- 顶部Logo区域 -->
      <div class="sidebar-header">
        <LogoTitle :to="logoTo" :title="title" />
      </div>
      
      <!-- 自定义菜单内容区域 -->
      <div class="sidebar-content">
        <slot name="sidebar"></slot>
      </div>
      
      <!-- 底部工具栏 -->
      <div class="sidebar-footer">
        <!-- 底部操作组件 -->
        <div class="sidebar-actions">
          <!-- 登录/用户信息 -->
          <div class="user-section">
            <UserMenu />
          </div>
          <!-- 主题切换 -->
          <ThemeToggle />
        </div>
      </div>
    </div>

    <!-- 右侧主内容区 -->
    <div class="main-content" :class="{ 'sidebar-hidden': !showSidebar }">
      <slot name="content"></slot>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import LogoTitle from './LogoTitle.vue'
import ThemeToggle from './ThemeToggle.vue'
import UserMenu from './UserMenu.vue'

interface Props {
  title: string
  logoTo?: string
  sidebarWidth?: string
}

withDefaults(defineProps<Props>(), {
  logoTo: '/apps',
  sidebarWidth: '22%'
})

// 侧边栏显示控制
const showSidebar = ref(true)

// 切换侧边栏
const toggleSidebar = () => {
  showSidebar.value = !showSidebar.value
}

// 暴露方法给父组件
defineExpose({
  toggleSidebar,
  showSidebar
})
</script>

<style scoped>
.sidebar-layout {
  display: flex;
  background-color: transparent;
  min-height: 100vh;
  padding: 0;
  gap: 0;
}

/* 左侧边栏样式 */
.sidebar {
  width: v-bind(sidebarWidth);
  flex-shrink: 0;
  background-color: transparent;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0;
  border-radius: 0;
}

/* 侧边栏头部 */
.sidebar-header {
  padding: 0 1rem;
  border-bottom: 1px solid rgba(var(--color-border-light), var(--opacity-border-light));
  flex-shrink: 0;
  background: rgba(var(--color-sidebar-light), var(--opacity-main));
  display: flex;
  align-items: center;
  border-radius: 0;
}

/* 侧边栏内容区域 */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* 侧边栏底部 */
.sidebar-footer {
  flex-shrink: 0;
  padding: 16px;
  border-top: 1px solid rgba(var(--color-border-light), var(--opacity-border-light));
  background: rgba(var(--color-sidebar-light), var(--opacity-main));
  border-radius: 0;
}

.sidebar-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.user-section {
  display: flex;
  align-items: center;
}

/* 右侧内容区样式 */
.main-content {
  flex: 1;
  min-width: 0;
  background: transparent;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100vh;
  transition: margin-left 0.3s ease;
}

.main-content.sidebar-hidden {
  margin-left: 0;
}

/* 响应式适配 */
@media (max-width: 1200px) {
  .sidebar-layout {
    flex-direction: column;
    gap: 0.5rem;
  }

  .sidebar {
    width: 100%;
    height: auto;
    position: static;
  }

  .main-content {
    width: 100%;
    height: auto;
  }
}

@media (max-width: 768px) {
  .sidebar-layout {
    padding: 0.25rem;
  }
  
  .sidebar {
    display: none !important;
  }
  
  .sidebar-header {
    padding: 12px 16px;
    justify-content: center;
  }
}

/* 深色模式适配 */
.dark .sidebar {
  background-color: #252525;
}

.dark .sidebar-header {
  background: #252525;
  border-bottom-color: rgba(var(--color-border-dark), var(--opacity-border-dark));
  border-radius: 0;
}

.dark .sidebar-content {
  background: #252525;
}

.dark .sidebar-footer {
  background: #252525;
  border-top-color: rgba(var(--color-border-dark), var(--opacity-border-dark));
  border-radius: 0;
}

.dark .main-content {
  background: transparent;
}
</style>